home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / CUGUK / C005.ZIP / LOG.C < prev    next >
Text File  |  1990-01-19  |  2KB  |  75 lines

  1. /********************************************************************
  2.  * C Users Group (U.K) C Source Code Library File CUGLIB.005        *
  3.  * Inquiries to: M. Houston, 36 Whetstone Clo. Farquhar Rd.         *
  4.  * Edgbaston, Birmingham B15 2QN ENGLAND                *
  5.  ********************************************************************
  6.  * File name: log.c
  7.  * Program name: library modules only
  8.  * Source of file: The Public Domain Software Library.
  9.  * Purpose: maths function
  10.  * Changes: <who what when & why major changes have been made>      
  11.  ********************************************************************/
  12.  
  13.  
  14. /***********************************************************
  15.  *               The TULSA IBM C BOARD                     *
  16.  *                   918-664-8737                          *
  17.  *             300/1200 XMODEM, 24 Hours                   *
  18.  **********************************************************/
  19.  
  20.  
  21. #include "math.h"
  22. #include "errno.h"
  23.  
  24. double log10(x)
  25. double x;
  26. {
  27.         return log(x)*0.43429448190325182765;
  28. }
  29.  
  30. #define A0 -0.64124943423745581147e+2
  31. #define A1 +0.16383943563021534222e+2
  32. #define A2 -0.78956112887491257267e+0
  33. #define A(w) ((A2*w A1)*w A0)
  34.  
  35. #define B0 -0.76949932108494879777e+3
  36. #define B1 +0.31203222091924532844e+3
  37. #define B2 -0.35667977739034646171e+2
  38. #define B(w) (((w B2)*w B1)*w B0)
  39.  
  40. #define C0 0.70710678118654752440
  41. #define C1 0.693359375
  42. #define C2 -2.121944400546905827679e-4
  43.  
  44. double log(x)
  45. double x;
  46. {
  47.         double Rz, f, z, w, znum, zden, xn;
  48.         int n;
  49.         extern int errno;
  50.  
  51.         if (x <= 0.0) {
  52.                 errno = EDOM;
  53.                 return -HUGE;
  54.         }
  55.         f = frexp(x, &n);
  56.         if (f > C0) {
  57.                 znum = (znum = f-0.5) - 0.5; /* the assignment prevents const. eval */
  58.                 zden = f*0.5 + 0.5;
  59.         } else {
  60.                 --n;
  61.                 znum = f - 0.5;
  62.                 zden = znum*0.5 + 0.5;
  63.         }
  64.         z = znum/zden;
  65.         w = z*z;
  66. /* the lines below are split up to allow expansion of A(w) and B(w) */
  67.         Rz = z + z * (w *
  68.                          A(w)
  69.                         /B(w));
  70.         xn = n;
  71.         return (xn*C2 + Rz) + xn*C1;
  72. }
  73.  
  74.  
  75.